<template>
  <div class="allCivil">
    <div class="header">
      <div class="titleContainer">
        <img :src="customerLogo" @click="handleLogoClick" />
        <span class="title" @click="handleLogoClick"> {{ customerDesc }} </span>
        <mineAvatar :isMine="false" />
      </div>
    </div>
    <div class="contentContainer" v-loading="loading">
      <div class="main">
        <div class="topNav">
          <div class="topNavItem">
            <div class="backBtn" title="返回" @click="handleBackBtnClick">
              <img :src="backBtn" alt="" />
            </div>
            <div class="navPositionName" v-if="civilPositionInfo.depart">
              {{
                `${civilPositionInfo.depart} · ${civilPositionInfo.employmentDepartment} · ${civilPositionInfo.jobName}`
              }}
            </div>
          </div>
        </div>
        <div class="mainContent">
          <el-scrollbar style="height: 100%">
            <div class="content">
              <div class="headerInfo">
                <span>更新截止至{{ civilPositionInfo.deadline }}</span>
              </div>
              <div class="dataOverview">
                <div
                  class="item"
                  v-for="item in dataOverviewList"
                  :key="item.name"
                >
                  <div class="beforeIcon">
                    <img :src="item.beforeIcon" class="beforeIconClass" />
                  </div>
                  <div class="dataItemContent">
                    <span class="dataItemName">{{ item.name }}</span>
                    <span class="dataItemValue">{{ item.value }}</span>
                  </div>
                  <img :src="item.afterIcon" class="afterIconClass" />
                </div>
              </div>
              <div class="uniInfo">
                <div class="title-box">
                  <div class="icon-box">
                    <img :src="hat" alt="" class="icon" />
                  </div>
                  <div class="uniTitle">单位信息</div>
                </div>
                <div class="grid-container gridRow2">
                  <div class="grid-item borderTop borderLeft">招录机关</div>
                  <div class="grid-item borderTop value">
                    {{ civilPositionInfo.depart }}
                  </div>
                  <div class="grid-item borderTop">部门代码</div>
                  <div class="grid-item borderTop value">
                    {{ civilPositionInfo.departCode || '-' }}
                  </div>
                  <div class="grid-item borderLeft">用人司局</div>
                  <div class="grid-item value">
                    {{ civilPositionInfo.employmentDepartment || '-' }}
                  </div>
                  <div class="grid-item">机构性质</div>
                  <div class="grid-item value">
                    {{ civilPositionInfo.agencyNature || '-' }}
                  </div>
                  <div class="grid-item borderLeft">机构层级</div>
                  <div class="grid-item value">
                    {{ civilPositionInfo.agencyLevel || '-' }}
                  </div>
                  <div class="grid-item">落户地点</div>
                  <div class="grid-item value">
                    {{ civilPositionInfo.settlePlace }}
                  </div>
                  <div class="grid-item borderLeft">工作地点</div>
                  <div class="grid-item value">
                    {{ civilPositionInfo.workPlace }}
                  </div>
                </div>
              </div>
              <div class="uniInfo">
                <div class="title-box">
                  <div class="icon-box">
                    <img :src="hat" alt="" class="icon" />
                  </div>
                  <div class="uniTitle">职位信息</div>
                </div>
                <div class="grid-container gridRow4">
                  <div class="grid-item borderTop borderLeft">职位名称</div>
                  <div class="grid-item borderTop value">
                    {{ civilPositionInfo.jobName }}
                  </div>
                  <div class="grid-item borderTop">职位代码</div>
                  <div class="grid-item borderTop value">
                    {{ civilPositionInfo.jobCode }}
                  </div>
                  <div class="grid-item borderLeft">职位属性</div>
                  <div class="grid-item value">
                    {{ civilPositionInfo.jobAttribute }}
                  </div>
                  <div class="grid-item">职位分布</div>
                  <div class="grid-item value">
                    {{ civilPositionInfo.jobDistribution }}
                  </div>
                  <div class="grid-item">招录人数</div>
                  <div class="grid-item value">
                    {{ civilPositionInfo.jobPeopleNum }}
                  </div>
                  <div class="grid-item">考试类别</div>
                  <div class="grid-item value">
                    {{ civilPositionInfo.examCategory }}
                  </div>
                  <div class="grid-item">职位简介</div>
                  <div class="grid-item value span3">
                    {{ civilPositionInfo.jobIntroduction }}
                  </div>
                </div>
              </div>
              <div class="uniInfo">
                <div class="title-box">
                  <div class="icon-box">
                    <img :src="hat" alt="" class="icon" />
                  </div>
                  <div class="uniTitle">报考条件</div>
                </div>
                <div class="grid-container gridRow3">
                  <div class="grid-item borderTop borderLeft">专业</div>
                  <div class="grid-item borderTop value">
                    {{ civilPositionInfo.major }}
                  </div>
                  <div class="grid-item borderTop">政治面貌</div>
                  <div class="grid-item borderTop value">
                    {{ civilPositionInfo.politicalStatusDesc }}
                  </div>
                  <div class="grid-item borderLeft">学历</div>
                  <div class="grid-item value">
                    {{ civilPositionInfo.eduDesc }}
                  </div>
                  <div class="grid-item">学位</div>
                  <div class="grid-item value">
                    {{ civilPositionInfo.degreeDesc }}
                  </div>
                  <div class="grid-item">基层工作最低年限</div>
                  <div class="grid-item value">
                    {{ civilPositionInfo.workYearDesc }}
                  </div>
                  <div class="grid-item">服务基层项目工作经历</div>
                  <div class="grid-item value">
                    {{ civilPositionInfo.workHistory }}
                  </div>
                </div>
              </div>
              <div class="uniInfo">
                <div class="title-box">
                  <div class="icon-box">
                    <img :src="hat" alt="" class="icon" />
                  </div>
                  <div class="uniTitle">其他信息</div>
                </div>
                <div class="grid-container gridRow1">
                  <div class="grid-item borderTop borderLeft">
                    是否在面试阶段组织专业能力考试
                  </div>
                  <div class="grid-item borderTop value">
                    {{ civilPositionInfo.examHistory }}
                  </div>
                  <div class="grid-item borderTop">面试人员比例</div>
                  <div class="grid-item borderTop value">
                    {{ civilPositionInfo.interviewRate || '-' }}
                  </div>
                  <div class="grid-item borderLeft">部门网站</div>
                  <div class="grid-item value">
                    <a
                      target="_blank"
                      @click="
                        handleWebsiteClick(civilPositionInfo.departWebsite)
                      "
                      >{{ civilPositionInfo.departWebsite || '-' }}</a
                    >
                  </div>
                </div>
              </div>
              <div class="uniInfo">
                <div class="title-box">
                  <div class="icon-box">
                    <img :src="hat" alt="" class="icon" />
                  </div>
                  <div class="uniTitle">备注</div>
                </div>
                <div class="textArea">
                  {{ civilPositionInfo.jobDesc }}
                </div>
              </div>
              <div class="tips">
                免责声明：提示广大考生，请报考前仔细阅读对应职位招录要求或联系招录单位确认，本职位检索系统提供内容仅供参考。
              </div>
            </div>
          </el-scrollbar>
        </div>
      </div>
    </div>
    <freeDialog />
  </div>
</template>

<script>
import freeDialog from "@/components/freeDialog";
import { getCivilPositionInfo } from '@/api/civil-job';
import backBtn from '@/icons/backBtn.png';
import ztLogo from '@/assets/home/zt-logo.png';
import governmentIcon from '@/assets/home/governmentIcon.png';

export default {
  name: 'Detail',
  components: {freeDialog,
    mineAvatar: () => import('../home/components/mineAvatar'),},
  data() {
    return {
      from:"",
      customerDesc: '',
      hat: 'https://img3.job1001.com/data_center/images/hat.png',
      governmentIcon,
      SecretKey: '',
      customerLogo: '',
      pageTitle: '',
      backBtn,
      ztLogo,
      wxImg: '',
      showGlass: false,
      loading: false,
      id: '',
      year: '',
      civilPositionInfo: {},
      dataOverviewList: [
        {
          name: `招录人数`,
          value: 454,
          beforeIcon:
            'https://img3.job1001.com/data_center/images/beforeIcon1.png',
          afterIcon:
            'https://img3.job1001.com/data_center/images/afterIcon1.png'
        },
        {
          name: '报名人数',
          value: 454,
          beforeIcon:
            'https://img3.job1001.com/data_center/images/beforeIcon2.png',
          afterIcon:
            'https://img3.job1001.com/data_center/images/afterIcon2.png'
        },
        {
          name: `过审人数`,
          value: 1454,
          beforeIcon:
            'https://img3.job1001.com/data_center/images/beforeIcon3.png',
          afterIcon:
            'https://img3.job1001.com/data_center/images/afterIcon3.png'
        },
        {
          name: '最高竞争比',
          value: '23243:1',
          beforeIcon:
            'https://img3.job1001.com/data_center/images/beforeIcon4.png',
          afterIcon:
            'https://img3.job1001.com/data_center/images/afterIcon4.png'
        },
        {
          name: '入面分数线',
          value: '109',
          beforeIcon:
            'https://img3.job1001.com/data_center/images/beforeIcon5.png',
          afterIcon:
            'https://img3.job1001.com/data_center/images/afterIcon5.png'
        }
      ]
    };
  },
  async created() {
    //特殊情况(from=ylIndex)下不展示mineAvatar组件
    this.from=sessionStorage.getItem("from")||this.$route.query.from;

    this.SecretKey = this.$route.query.SecretKey;
    this.id = this.$route.query.id;
    this.year = this.$route.query.year;
    if (localStorage.getItem('customerDesc')) {
      this.customerDesc = localStorage.getItem('customerDesc');
      document.title = this.customerDesc;
    }

    const extraJson = localStorage.getItem('extra');
    if (extraJson) {
      const extra = JSON.parse(extraJson);
      this.customerLogo = extra.icon ? extra.icon : this.governmentIcon;
    } else {
      this.customerLogo = this.governmentIcon;
    }

    const superToken = localStorage.getItem('superToken');
    if (superToken) {
      this.pageTitle = localStorage.getItem('customerDesc');
    } else {
      this.pageTitle = '职神籍';
    }

    await this.getCivilPositionInfoFn();
  },
  methods: {
    checkString(val) {
      if (val == '0' || val == '0.0' || !val) {
        return '-';
      } else {
        return val;
      }
    },
    async getCivilPositionInfoFn() {
      this.loading = true;
      const res = await getCivilPositionInfo({ id: this.id });
      this.loading = false;
      if (res.code == 200) {
        this.civilPositionInfo = res.data;
        this.dataOverviewList[0].name = this.year + '年招录人数';
        this.dataOverviewList[0].value = this.checkString(
          res.data.jobPeopleNum
        );
        this.dataOverviewList[1].name = this.year + '年报名人数';
        this.dataOverviewList[1].value = this.checkString(
          res.data.peopleSubmitNum
        );
        this.dataOverviewList[2].name = this.year + '年过审人数';
        this.dataOverviewList[2].value = this.checkString(
          res.data.peopleQualifiedNum
        );
        let competitionRatio = res.data.competitionRatio
          ? res.data.competitionRatio.replace(':', ' : ')
          : '-';
        this.dataOverviewList[3].name = this.year + '年最高竞争比';
        this.dataOverviewList[3].value = competitionRatio;
        this.dataOverviewList[4].name = this.year + '年入面分数线';
        this.dataOverviewList[4].value = this.checkString(res.data.passScore);

        this.$bus.$emit("generalReportAction", {
          etId: 40046,
          personId: localStorage.getItem("personId"),
          cardType: localStorage.getItem("cardType"),
          jumpSource: 60,
          sourceType: 60,
          eventData: this.civilPositionInfo.jobName,
        });

      }
    },
    handleWebsiteClick(value) {
      let url = value;
      if (!value.includes('//')) {
        url = '//' + value;
      }
      window.open(url, '_blank');
    },
    handleBackBtnClick() {
      if (this.from == "ylIndex") {
        this.$router.push({
          path: "/freehome",
          query: {
            from: this.$route.query.from,
          },
        });
        return;
      } 
      this.$store.dispatch('settings/changeSetting', {
        key: 'showType',
        value: 'civil'
      });
      this.$router.push({
        path: '/position',
        query: {
          superToken: this.$route.query.superToken || '',
          SecretKey: this.$route.query.SecretKey || ''
        }
      });
    },
    handleLogoClick() {
      if(this.from=='ylIndex'){
        this.$router.push({
        path: '/freehome',
        query: {
          from:'ylIndex'
        }
      });
      }else{

        this.$store.dispatch('settings/changeSetting', {
        key: 'showType',
        value: 'position'
      });
      this.$router.push({
        path: '/position',
        query: {
          superToken: this.$route.query.superToken || '',
          SecretKey: this.$route.query.SecretKey || '',
          customerName: this.$route.query.customerName || ''
        }
      });
      }
    },
    handleMine() {
      this.$router.push({
        path: '/mine',
        query: {
          id: this.$route.query.id,
          superToken: this.$route.query.superToken || '',
          SecretKey: this.$route.query.SecretKey || '',
          customerName: this.$route.query.customerName
        }
      });
    }
  }
};
</script>
<style scoped lang="scss">
::v-deep .el-scrollbar__wrap {
  overflow-x: hidden;
}
.allCivil {
  position: relative;
  background: #f7f8fa;
  height: 100%;
  min-width: 1190px;
  .glass {
    width: 100%;
    height: 100%;
    background: rgba(22, 22, 22, 0.6);
    backdrop-filter: blur(3px);
    position: absolute;
    top: 0;
    z-index: 9999;
    display: flex;
    flex-direction: row;
    justify-content: center;
    padding-top: 20%;
    .wx-card {
      width: 361px;
      height: 316px;
      background-image: url('../../assets/home/wx-bg.png');
      background-size: 100% 100%;
      padding: 23px;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      .title {
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: center;
        margin-bottom: 20px;
        img {
          width: 28px;
          height: 28px;
        }
        span {
          font-weight: 800;
          font-size: 16px;
          color: #141416;
        }
      }
      .desc {
        margin-bottom: 19px;
      }
      .wx {
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: center;
        margin-bottom: 15px;
        background-color: #ffffff;
        padding: 3px 3px 4px 4px;
        border-radius: 4px;
        img {
          width: 148px;
          height: 148px;
        }
      }
      .name {
        font-family: PingFang-SC, PingFang-SC;
        font-weight: bold;
        font-size: 15px;
        color: #333333;
      }
    }
  }
  .header {
    position: fixed;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 57px;
    width: 100%;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(7px);
    background-size: 100% 57px;
    z-index: 2;
    .titleContainer {
      display: flex;
      align-items: center;
      padding-left: 25px;
      color: #fff;
      font-size: 17px;
      line-height: 24px;
      letter-spacing: 2px;
      .title {
        font-family: 'title-home-font';
        cursor: pointer;
        max-width: 26vw;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-inline-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 1;
      }
      img {
        height: 24px;
        width: auto;
        cursor: pointer;
        margin-right: 5px;
      }
    }
    .mine {
      color: #fff;
      cursor: pointer;
      display: flex;
      align-items: center;
      font-size: 14px;
      .avator {
        height: 24px;
        width: 24px;
        margin: 0 24px 0 8px;
        border-radius: 50%;
        overflow: hidden;
      }
    }
  }
  .contentContainer {
    width: 100%;
    height: 100%;
    padding-top: 52px;
    display: flex;
    background: url('../../assets/home/back.png') no-repeat;
    flex-direction: column;
    background-size: 100.1% auto;
    align-items: center;
    min-width: 1375px;
    .experienceTime {
      height: 28px;
      z-index: 3;
      position: absolute;
      top: 16px;
      right: 110px;
      display: flex;
      flex-direction: row;
      align-items: center;
      color: #ffffff;
      .time {
        margin-left: 9px;
        display: flex;
        flex-direction: row;
        align-items: center;
        .time-box {
          width: 56px;
          height: 28px;
          padding: 4px 8px; /* 内边距 */
          border: 1px solid #5e6d84; /* 边框 */
          border-radius: 4px; /* 圆角 */
          box-shadow: 0 0 5px rgba(0, 0, 0, 0.3); /* 阴影 */
          margin: 0 4px;
          font-family: D-DIN-PRO-500-Medium;
          font-weight: bold;
          font-size: 15px;
          color: #ffffff;
        }
        .dot {
          height: 18px;
          display: flex;
          flex-direction: column;
          justify-content: space-evenly;
          div {
            width: 4px;
            height: 4px;
            background: #ffffff;
            border-radius: 50%;
          }
        }
      }
    }
    .main {
      height: calc(100% - 25px);
      position: relative;
      border-radius: 20px;
      margin-top: 24px;
      background-color: white;
      width: calc(100vw - 34px);
      min-width: 1375px;
      display: flex;
      flex-direction: column;
      .topNav {
        display: flex;
        align-items: center;
        justify-content: space-between;
        height: 60px;
        padding: 0 16px;
        .topNavItem {
          display: flex;
          width: 100%;
        }
        .topNavItemRight {
          display: flex;
          align-items: center;
          padding-right: 65px;
        }
        .backBtn {
          width: 36px;
          height: 36px;
          margin-right: 16px;
          cursor: pointer;
          img {
            width: 36px;
            height: 36px;
          }
        }
        .navPositionName {
          font-size: 18px;
          font-family: PingFangSC-Medium, PingFang SC;
          font-weight: 600;
          color: #222222;
          line-height: 28px;
          padding: 3px 16px 0 24px;
          margin: 0 -16px 0 -23px;
          width: 100%;
          border-bottom: 1px solid #cfd8f5;
        }
      }
      .mainContent {
        width: 100%;
        height: calc(100% - 60px);
        box-shadow: 0px 24px 32px -22px #d7e3f8 inset;
        .content {
          padding: 17px 0 0 24px;
        }
        .headerInfo {
          font-family: PingFangSC, PingFang SC;
          font-weight: 400;
          font-size: 14px;
          color: #666666;
          margin-bottom: 18px;
          > span {
            margin-right: 6px;
          }
        }
        .dataOverview {
          display: grid;
          grid-template-columns: repeat(5, 1fr);
          gap: 10px;
          margin: 20px 24px 10px 0;
          .item {
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 18px;
            border-radius: 8px;
            border: 1px solid #eaedf7;
            .beforeIcon {
              border-radius: 8px;
              margin-right: 12px;
              .beforeIconClass {
                width: 44px;
                height: 44px;
              }
            }
            .dataItemContent {
              display: flex;
              flex-direction: column;
              .dataItemName {
                font-family: PingFangSC, PingFang SC;
                font-weight: 400;
                font-size: 14px;
                color: #a2a5b3;
                margin-bottom: 5px;
              }
              .dataItemValue {
                font-family: D-DIN-PRO-800-ExtraBold;
                font-weight: bold;
                font-size: 24px;
                color: #242f57;
              }
            }
            .afterIconClass {
              width: 44px;
              height: 44px;
              margin-left: auto;
            }
          }
          .locationBox {
            display: block;
            border-radius: 8px;
            background: #f4faff;
            font-family: PingFang-SC, PingFang-SC;
            font-weight: bold;
            font-size: 16px;
            .year {
              margin-bottom: 12px;
            }
          }
        }
        .uniInfo {
          margin-bottom: 18px;
          margin-right: 24px;
          &:last-child {
            margin-bottom: 0;
          }
          .title-box {
            display: flex;
            align-items: center;
            margin-bottom: 4px;
            .icon-box {
              display: flex;
              z-index: 2;
              border: 6px solid #fff;
              border-radius: 50%;
              border-left: none;
              .icon {
                width: 32px;
                height: 32px;
              }
            }
            .uniTitle {
              flex: 1;
              font-family: PingFang-SC, PingFang-SC;
              font-weight: bold;
              font-size: 16px;
              color: #222222;
              background: #f3f9fe;
              padding: 8px 0 8px 32px;
              margin-left: -24px;
              z-index: 1;
            }
          }
          .grid-container {
            display: grid;
            grid-template-columns: repeat(4, 1fr);
          }

          .gridRow1 {
            grid-template-rows: repeat(1, auto);
          }
          .gridRow2 {
            grid-template-rows: repeat(2, auto);
          }
          .gridRow3 {
            grid-template-rows: repeat(3, auto);
          }
          .gridRow4 {
            grid-template-rows: repeat(4, auto);
          }
          .span3 {
            grid-column: span 3;
          }

          .grid-item {
            border-bottom: 1px solid #e8e8e8;
            border-right: 1px solid #e8e8e8;
            display: flex;
            justify-content: center;
            align-items: center;
            font-size: 14px;
            color: #333333;
            padding: 10px 8px;
            line-height: 20px;
            &:nth-child(2n + 1) {
              background: #f4f4f4;
            }
          }
          .value {
            color: #222222;
            font-size: 15px;
          }
          .borderTop {
            border-top: 1px solid #e8e8e8;
          }
          .borderLeft {
            border-left: 1px solid #e8e8e8;
          }
          .textArea {
            padding: 12px;
            border: 1px solid #e8e8e8;
            color: #333333;
            font-size: 14px;
            line-height: 24px;
          }
        }
        .tips {
          font-family: PingFangSC, PingFang SC;
          font-weight: 400;
          font-size: 13px;
          color: #666;
          padding: 0 0 24px 0;
        }
      }
    }
  }
}
.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.5s ease;
}

.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}
</style>
